package com.azure.bigstore.service;

import com.azure.bigstore.entity.User;
import com.azure.bigstore.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by Azure on 2018/1/23.
 */
@Service
public class UserService {

    @Autowired
    private UserRepository userRepository;

    public User findById(Long id){
        return userRepository.findOne(id);
    }
    public User findByUsernameAndPassword(String email, String password){
        return userRepository.findByUsernameAndPassword(email,password);
    }
    public User findByUsername(String email){
        return  userRepository.findByUsername(email);
    }

    public String saveUser(User user){
        if(user != null){
            return userRepository.save(user) != null ? "1" : "0";
        }else{
            return "-2";
        }
    }

    public User findUserInfo(long id){
        User u = userRepository.findOne(id);
        System.out.println("findUserInfo>>"+u);
        return new User("","",u.getAddr_sheng(),u.getAddr_shi(),u.getAddr_qu_xian(),u.getAddr_xiang_jiedao(),u.getAddr_other(),u.getName(),u.getPhone(),new Date());
    }
}
